package com.treasure.mall.biz.repository.product;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.product.ProductImgPO;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wm
 */
@Repository
public interface ProductImgRepository extends JpaSearchableRepository<ProductImgPO, Long> {
    @Query("delete from ProductImgPO pi where pi.productId=?1")
    @Modifying(clearAutomatically = true)
    @Transactional(rollbackFor = RuntimeException.class)
    void deleteByProductId(Long productId);

    List<ProductImgPO> findAllByProductIdOrderBySortNoAsc(Long productId);
}